<template>
  <div class="app-container">
    <el-row>
      <el-col :span="16">
        <el-calendar :first-day-of-week="1" v-model="calendarValue">
          <!-- 插槽 -->
          <template slot="dateCell" slot-scope="{date, data}">
            <!--  date   单元格代表的日期  data { type, isSelected, day}，type 表示该日期的所属月份，可选值有 prev-month，current-month，next-month；isSelected 标明该日期是否被选中；day 是格式化的日期，格式为 yyyy-MM-dd-->
            <div class="tb-cell">
              <!-- 这里加了周六周天的判断 -->
              <div :class="(date.getDay()==6 || date.getDay()==0)?'weeked' :'notweeked'">
                {{ data.day.substring(8) }}
              </div>
              <!-- 数组循环 -->
              <div class="cell" v-for="(item,index) in rlData">
                <!-- 加数据 -->
                <div v-if="data.day == item.day">
                  <div v-for="(it,iIndex) in rlData[index].data">
                    <div class="info mt10" @click="itemClick(it)">
                      <div class="schedule">
                        <!--                    <i class="el-icon-info"></i>-->
                        {{ it.time }}
                        <dict-tag :options="dict.type.fs_aj_ktlx" :value="it.ktfs"/>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </el-calendar>
      </el-col>
      <el-col :span="8">

        <el-table class="detailTb" v-loading="loading" :data="opencourtList">
          <el-table-column label="开庭信息" align="center">
            <template slot-scope="scope">
              <span class="btn" @click="handleDetail(scope.row.id)">
                <span>识别码: {{ scope.row.fsCase.nbajbh }}</span><br>
                <span>案号: {{ scope.row.ah }}</span><br>
                <span>{{ scope.row.fsCase.ajmc }}</span><br>
                <span>{{ scope.row.fymc }}</span>
                <span v-if="scope.row.ft != null">&nbsp;-&nbsp;{{ scope.row.ft }}</span>
                <br>
                <span class="important">{{ parseTime(scope.row.ktrq, '{y}-{m}-{d}') }}</span>
                &nbsp;&nbsp;
                <span class="important">{{ scope.row.ktsj }}</span>
                <dict-tag :options="dict.type.fs_aj_ktlx" :value="scope.row.ktfs"/>
              </span>
            </template>
          </el-table-column>
        </el-table>

      </el-col>
    </el-row>


    <!-- 开庭详情 -->
    <el-dialog class="ktxq" :title="xqtitle" :visible.sync="xqopen" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="案号">
              {{ form.ah }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="案件名称">
              {{ fsCase.ajmc }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="资产包">
              {{ fsCase.zfName }}&nbsp;&nbsp;{{ fsCase.batchName }}&nbsp;&nbsp;{{ fsCase.ssztmc }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="被告信息">
              {{ bgDsr.xm }}&nbsp;&nbsp;
              <dict-tag :options="dict.type.sys_user_sex" :value="bgDsr.xb"/>&nbsp;&nbsp;
              {{ bgDsr.zjhm }}&nbsp;&nbsp;
              电话：{{ bgDsr.sjhm }}&nbsp;&nbsp;<br>
              地址：{{ bgDsr.dz }}&nbsp;&nbsp;
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开庭信息">
              {{ form.fymc }} &nbsp;&nbsp;<br> <b>{{ form.ktrq }}&nbsp;&nbsp;{{ form.ktsj }}&nbsp;&nbsp;</b>
              {{ form.ft }}&nbsp;&nbsp;
              <dict-tag :options="dict.type.fs_aj_ktlx" :value="form.ktfs"/>
            </el-form-item>
          </el-col>
          <el-col v-if="form.fgxx != null" :span="24">
            <el-form-item label="法官信息">
              {{ form.fgxx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.dlls != null" :span="24">
            <el-form-item label="代理律师">
              {{ form.dlls }}&nbsp;&nbsp;{{ form.dllssjh }}
              <br>
              <template v-for="(item,index) in form.lsFiles">
                <el-link :key="index" type="primary" :href="item.oosUrl" target="_blank">{{ item.name }}</el-link>
              </template>
            </el-form-item>
          </el-col>
          <el-col v-if="form.ktdx != null" :span="24">
            <el-form-item label="开庭短信">
              {{ form.ktdx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.ktcpxx != null || ktFiles.length>0" :span="24">
            <el-form-item label="开庭传票">
              {{ form.ktcpxx }}
              <br>
              <template v-for="(item,index) in form.ktFiles">
                <el-link :key="index" type="primary" :href="item.oosUrl" target="_blank">{{ item.name }}</el-link>
              </template>
            </el-form-item>
          </el-col>
          <el-col v-if="form.xcxxx != null" :span="24">
            <el-form-item label="小程序">
              {{ form.xcxxx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.tjfa != null" :span="24">
            <el-form-item label="调解方案">
              {{ form.tjfa }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="xqcancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOpencourt, getOpencourt,
  getRl
} from "@/api/fs/opencourt";
import {formatDate} from "@/api/fs/common";

export default {
  name: 'KTTX',
  dicts: ['fs_yes_no', 'fs_aj_ktlx', 'sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      opencourtList: [],
      oldValue: new Date(),
      calendarValue: new Date(),
      rlData: [],
      dialogVisible: false,
      title: '',
      content: '',
      // 日期范围
      dateRange: [],
      ktFiles: [],
      lsFiles: [],
      // 弹出层标题
      xqtitle: "",
      // 是否显示弹出层
      open: false,
      xqopen: false,
      // 表单参数
      form: {},
      lsform: {},
      fsCase: {},
      bgDsr: {},
      queryParams: {
        ktrq: null,
      },
    }
  },
  created() {
    this.oldValue = this.formatDate(new Date());
    this.calendarValue = this.formatDate(new Date());
    this.getRlData();
    this.getTableData();
  },
  watch: {
    calendarValue(newVal, oldVal) {
      this.calendarValue = this.formatDate(newVal)
      // 这里就是我们处理数据，调用接口的位置
      this.judgeDate()
    }
  },
  methods: {
    formatDate(date) {
      const value = new Date(date)
      const year = value.getFullYear()
      const month = (value.getMonth() + 1).toString().padStart(2, '0')
      const day = value.getDate().toString().padStart(2, '0')
      return `${year}-${month}-${day}`
    },
    judgeDate() {
      if (this.oldValue != this.calendarValue) {
        console.log(this.calendarValue);
        this.oldValue = this.calendarValue;
        this.getTableData();
      }
    },
    getTableData() {
      this.queryParams.ktrq = this.calendarValue
      listOpencourt(this.queryParams).then(response => {
        this.opencourtList = response.rows;
        this.loading = false;
      });
    },
    itemClick(data) {
      console.log(data)
      this.handleDetail(data.id);
    },
    getRlData() {
      getRl().then(response => {
        this.rlData = response.data;
      });
    },
    xqcancel() {
      this.xqopen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        processId: null,
        ah: null,
        caseId: null,
        fyid: null,
        fymc: null,
        ft: null,
        ktfs: null,
        ktrq: null,
        ktsj: null,
        tjy: null,
        fgxx: null,
        dllsid: null,
        dlls: null,
        lszjUrl: null,
        ktdx: null,
        ktcpxx: null,
        ktcpUrl: null,
        xcxxx: null,
        tjfa: null,
        zjzb: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        lsFiles: [],
        ktFiles: [],
        fileUrls: null,
        fsCase: null,
      };
      this.resetForm("form");
    },
    resetXq() {
      this.reset(),
        this.fsCase = {
          id: null,
          localId: null,
          bh: null,
          ah: null,
          bhLs: null,
          yg: null,
          ygbh: null,
          bg: null,
          bgbh: null,
          ajlx: null,
          ajlxMc: null,
          ajmc: null,
          bzqx: null,
          fyid: null,
          fymc: null,
          dzlx: null,
          sqbdje: null,
          sqlaay: null,
          sqlx: null,
          sqlxMc: null,
          zt: null,
          cjsj: null,
          gxsj: null,
          ownerId: null,
          owner: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          ajzt: null,
          tjyId: null
        };
      this.bgDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
    },
    handleDetail(id) {
      this.resetXq();
      getOpencourt(id).then(response => {
        let row = response.data;
        this.form = row;
        let ktrq = formatDate(row.ktrq, 'yyyy-MM-dd');
        this.form.ktrq = ktrq;
        this.fsCase = row.fsCase;
        this.bgDsr = row.fsCase.bgDsr;
        this.ktFiles = row.ktFiles;
        this.lsFiles = row.lsFiles;
        this.xqopen = true;
        this.xqtitle = "开庭详情";
      });
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .is-today {
  .weeked {
    background-color: #ff000099;
  }
}

div ::v-deep th.gutter {
  display: initial;
}

div ::v-deep .el-calendar-day {
  min-height: 120px;
  height: inherit !important;
  position: relative;
  z-index: inherit;
}

.notweeked, {
  //display: inline-block;
  padding: 0px;
  text-align: left;
  font-size: 15px;
}

.weeked {
  //display: inline-block;
  padding: 0px;
  text-align: left;
}

.schedule {
  position: relative;

  &::before {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    content: '';
    width: 4px;
    background-color: #409eff;
  }

  padding: 3px 2px;
  padding-left: 8px;
  background-color: #409eff33;
  font-size: 14px;
  font-weight: 550;
}

.cell {
  .info {
    word-break: break-all;
  }
}

.schedule div {
  display: inline-block;
}

.detail .el-form-item {
  margin-bottom: 0px;
}

.el-collapse-item__header {
  font-size: 16px !important;
  font-weight: 600 !important;
}

.el-table__cell .cell div {
  display: inline;
}

.el-table__cell .cell .btn {
  cursor: pointer;
}

.cellBtn button {
  font-size: 20px !important;
  padding: 0 !important;
}

.hktable .el-table__cell .cell div {
  display: inline-block;
}

.el-table__cell .cell .important {
  font-weight: 600;
}

.el-form-item__content div {
  display: inline-block;
}

.ktxq .el-dialog__body {
  padding: 0px 20px;
}

.ktxq .el-form-item {
  margin-bottom: 5px;
}

thead th div {
  font-size: 15px !important;
  line-height: 32px !important;
}
</style>
